home *** CD-ROM | disk | FTP | other *** search
/ Ultra Pack / UltraComputing Partner Applications.iso / SunLabs / tclTK / src / tcl7.4 / tests / incr.test < prev    next >
Encoding:
Text File  |  1994-12-18  |  2.6 KB  |  89 lines

  1. # Commands covered:  lreplace
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1991-1993 The Regents of the University of California.
  8. # Copyright (c) 1994 Sun Microsystems, Inc.
  9. #
  10. # See the file "license.terms" for information on usage and redistribution
  11. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  12. #
  13. # @(#) incr.test 1.7 94/12/17 16:20:02
  14.  
  15. if {[string compare test [info procs test]] == 1} then {source defs}
  16.  
  17. catch {unset x}
  18.  
  19. test incr-1.1 {basic incr operation} {
  20.     set x 23
  21.     list [incr x] $x
  22. } {24 24}
  23. test incr-1.2 {basic incr operation} {
  24.     set x 106
  25.     list [incr x -5] $x
  26. } {101 101}
  27. test incr-1.3 {basic incr operation} {
  28.     set x "  -106"
  29.     list [incr x 1] $x
  30. } {-105 -105}
  31. test incr-1.3 {basic incr operation} {
  32.     set x "  +106"
  33.     list [incr x 1] $x
  34. } {107 107}
  35.  
  36. test incr-2.1 {incr errors} {
  37.     list [catch incr msg] $msg
  38. } {1 {wrong # args: should be "incr varName ?increment?"}}
  39. test incr-2.2 {incr errors} {
  40.     list [catch {incr a b c} msg] $msg
  41. } {1 {wrong # args: should be "incr varName ?increment?"}}
  42. test incr-2.3 {incr errors} {
  43.     catch {unset x}
  44.     list [catch {incr x} msg] $msg $errorInfo
  45. } {1 {can't read "x": no such variable} {can't read "x": no such variable
  46.     while executing
  47. "incr x"}}
  48. test incr-2.4 {incr errors} {
  49.     set x abc
  50.     list [catch {incr x} msg] $msg $errorInfo
  51. } {1 {expected integer but got "abc"} {expected integer but got "abc"
  52.     (reading value of variable to increment)
  53.     invoked from within
  54. "incr x"}}
  55. test incr-2.5 {incr errors} {
  56.     set x 123
  57.     list [catch {incr x 1a} msg] $msg $errorInfo
  58. } {1 {expected integer but got "1a"} {expected integer but got "1a"
  59.     (reading increment)
  60.     invoked from within
  61. "incr x 1a"}}
  62. test incr-2.6 {incr errors} {
  63.     proc readonly args {error "variable is read-only"}
  64.     set x 123
  65.     trace var x w readonly
  66.     list [catch {incr x 1} msg] $msg $errorInfo
  67. } {1 {can't set "x": variable is read-only} {can't set "x": variable is read-only
  68.     while executing
  69. "incr x 1"}}
  70. catch {unset x}
  71. test incr-2.7 {incr errors} {
  72.     set x -
  73.     list [catch {incr x 1} msg] $msg
  74. } {1 {expected integer but got "-"}}
  75. test incr-2.8 {incr errors} {
  76.     set x {  -  }
  77.     list [catch {incr x 1} msg] $msg
  78. } {1 {expected integer but got "  -  "}}
  79. test incr-2.9 {incr errors} {
  80.     set x +
  81.     list [catch {incr x 1} msg] $msg
  82. } {1 {expected integer but got "+"}}
  83. test incr-2.10 {incr errors} {
  84.     set x {20 x}
  85.     list [catch {incr x 1} msg] $msg
  86. } {1 {expected integer but got "20 x"}}
  87.  
  88. concat {}
  89.